package cn.com.code.hwjs;

import java.util.Scanner;

/**
 * 单词倒排
 * https://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836?tpId=37&tqId=38366&rp=1&ru=/exam/oj&qru=/exam/oj&sourceUrl=%2Fexam%2Foj%3Fpage%3D1%26pageSize%3D50%26search%3D%26tab%3D%25E5%2590%258D%25E4%25BC%2581%25E7%25AC%2594%25E8%25AF%2595%25E7%259C%259F%25E9%25A2%2598%26topicId%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=
 *
 * @author zhengpei
 * @date 2022/5/22
 */
public class Hwjs31 {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    while (scanner.hasNext()) {
      String s = scanner.nextLine();

      System.out.println(result(s));

    }
  }

  public static String result(String str) {
    // 匹配非字母的字符进行分割
    String[] words = str.split("[^A-Za-z]");
    StringBuilder result = new StringBuilder();

    // 逆序添加分割完的单词
    for (int i = words.length - 1; i >= 0; i--) {
      result.append(words[i]).append(" ");
    }
    return result.toString().trim();
  }


}
